package cn.findviewbydream.vant.plugin;

import java.util.Arrays;

/**
 * cn.findviewbydream.vant.plugin
 *
 * @author 白雨浓
 * date: 2019/11/12 10:27
 * content:
 */
public class Test {

    public static void main(String[] args) {
        fun(new int[]{7, 3, 8, 9, 6, 1, 8, 1, 2, 7, 7, 3, 4, 5}, 14, 10);
    }

    private static void fun(int[] a, int n, int max) {

        int[] temp = new int[n];
        int[] count = new int[max];

        for (int i = 0; i < n; i++) {
            temp[i] = a[i];
        }
        for (int i = 0; i < max; i++) {
            count[i] = 0;
        }
        for (int i = 0; i < n; i++) {
            count[a[i]] = count[a[i]] + 1;
        }
        System.out.println(Arrays.toString(count));
        for (int i = 1; i < max; i++) {
            count[i] = count[i - 1] + count[i];
        }
        System.out.println(Arrays.toString(count));
        for (int i = n - 1; i >= 0; i--) {
            a[--count[temp[i]]] = temp[i];
        }
        System.out.println(Arrays.toString(count));

    }
}
